/**
 * crawler
 *
 * outlook@China software studio
 * Copyright (c) 2008-2010. All Rights Reserved.
 * http://www.outlook.com
 */

package org.outlook.crawler.util.parser;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * function:
 * @author Watson email: watson.wu@hotmail.com
 * @date 2011
 */
public class ScriptParser {

	
	private static final String regex = "([A-Za-z|0-9]*)=(^[;]*?)";
	static Pattern pattern = Pattern.compile(regex);

	/**
	 * parse string like "abc=123; cdf=456"
	 * @param s
	 * @return
	 */
	public static Map<String, String> parse(String s) {
		Map<String, String> map = new HashMap<String, String>();
		if(!StringUtils.isBlank(s)) {
			Matcher matcher = pattern.matcher(s);
			while(matcher.find())
				map.put(matcher.group(1), matcher.group(2));
		}
		return map;
	}

}
